
export default {
  name: 'vFormItem',
  render(h) {
    let item = this.item
    if (this.itemKey.value instanceof Object) {
      this.itemKey.value = JSON.stringify(this.itemKey.value)
    }
    return (
      <elFormItem
        key={this.itemKey}
        prop={`${this.itemKey}.value`}
        required={item.required}
        rules={item.rule}
        label={item.label + '：'}
        style={item.type === 'hidden' ? 'height:0px' : ''}
      >
        {
          item.type === 'select' ? <vSelect option={item} /> : (
            item.type === 'radio' ? <vRadio option={item} /> : (
              item.type === 'checkbox' ? <vCheckbox option={item} /> : (
                item.type === 'upLoad' ? <vUpLoad option={item} /> : (
                  item.type === 'date' ? <vDate option={item}></vDate> : <vInput option={item} />))
            )
          )
        }
        {
          item.helper ? <i onClick={this.viewHelp.bind(this, item.helper)} class="fa fa-question-circle-o helper-icon"></i> : null
        }
        {item.text ? <span class="el-text">{item.text}</span> : null}
        {[...this.$slots.default || []]}
      </elFormItem>
    )
  },
  methods: {
    viewHelp(helper) {
      this.$alert(helper, '帮助提示', {
        showConfirmButton: false, customClass: 'helper-message'
      })
    }
  },
  props: ['item', 'itemKey']
}

